<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<!--
    pageNum 页码。页码从1开始，如：1，2，3，4，5，...
    offset 页码偏移量。如果页码是从0开始，则偏移量为-1；如果页码从1开始，偏移量为0
    pages 分页后，页的总数量。
    url URL地址。形如：/c , /c?id=1, /c/b?id=1&limit=10。

    1,会自动向url中添加页码，如：/c?id=1&page=1, /c/b?id=1&limit=10&page=1
    2,当超过totalPages>maxButtons时，会显示...代替多余的按钮
    3,maxButtons>=floatButtons*2
     -->
<div id="policy_pager" class="policy-pager pager layui-clear" th:fragment="page_pager(pageNum, offset, pages,total)"
     th:with="maxButtons=10,floatButtons=5">
    <div style="float: left;display: inline-block;">共<span th:text="${total}"></span>条记录</div>
    <ul class="pagination" style="float: right;display: inline-block; margin: 0 !important;">
        <!-- 上一页 -->
        <li th:if="${pageNum == 1}"><span>上一页</span></li>
        <li th:if="${pageNum > 1}"><a  th:onclick="'javascript:'+localRefresh+'('+${pageNum+offset-1}+')'">上一页</a></li>

        <!-- 首页 -->
        <li th:if="${pageNum == 1}" class="active"><span>1</span></li>
        <li th:if="${pageNum > 1}"><a th:onclick="'javascript:'+localRefresh+'('+${1+offset}+')'">1</a></li>

        <th:block th:if="${pages>2 && pages<=maxButtons}" th:each="i : ${#numbers.sequence(2,pages-1)}">
            <li th:if="${pageNum == i}" class="active"><span th:text="${i}">页码</span></li>
            <li th:if="${pageNum != i}"><a th:onclick="'javascript:'+localRefresh+'('+${i+offset}+')'" th:text="${i}">页码</a></li>
        </th:block>

        <th:block th:if="${pages > maxButtons}">
            <th:block th:if="${(pageNum-(floatButtons/2)) <= 2}" th:each="i : ${#numbers.sequence(2,2+floatButtons-1)}">
                <li th:if="${pageNum == i}" class="active"><span th:text="${i}">页码</span></li>
                <li th:if="${pageNum != i}"><a th:onclick="'javascript:'+localRefresh+'('+${i+offset}+')'" th:text="${i}">页码</a></li>
            </th:block>
            <!-- ... -->
            <li th:if="${(pageNum-(floatButtons/2))>2}"><span>...</span></li>

            <th:block
                    th:if="${((pageNum-(floatButtons/2))>2) && ((pageNum+(floatButtons/2)-(floatButtons%2==0?1:0)) < (pages-1))}"
                    th:each="i : ${#numbers.sequence(pageNum-(floatButtons/2),pageNum+(floatButtons/2)-(floatButtons%2==0?1:0))}">
                <li th:if="${pageNum == i}" class="active"><span th:text="${i}">页码</span></li>
                <li th:if="${pageNum != i}"><a th:onclick="'javascript:'+localRefresh+'('+${i+offset}+')'" th:text="${i}">页码</a></li>
            </th:block>

            <!-- ... -->
            <li th:if="${(pageNum+(floatButtons/2)-(floatButtons%2==0?1:0)) < (pages-1)}"><span>...</span></li>
            <th:block th:if="${(pageNum+(floatButtons/2)-(floatButtons%2==0?1:0)) >= (pages-1)}"
                      th:each="i : ${#numbers.sequence(pages-floatButtons,pages-1)}">
                <li th:if="${pageNum == i}" class="active"><span th:text="${i}">页码</span></li>
                <li th:if="${pageNum != i}"><a th:onclick="'javascript:'+localRefresh+'('+${i+offset}+')'" th:text="${i}">页码</a></li>
            </th:block>
        </th:block>

        <!-- 最后一页 -->
        <li th:if="${pages>1 && pageNum == pages}" class="active"><span th:text="${pages}">页码</span></li>
        <li th:if="${pages>1 && pageNum != pages}"><a th:onclick="'javascript:'+localRefresh+'('+${pages+offset}+')'"
                                                      th:text="${pages}">页码</a></li>

        <!-- 下一页 -->
        <li th:if="${pageNum >= pages}"><span>下一页</span></li>
        <li th:if="${pageNum < pages}"><a th:onclick="'javascript:'+localRefresh+'('+${pageNum+offset+1}+')'">下一页</a></li>
    </ul>
</div>
</html>